/** @type {import('webpack').Configuration} */
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')

module.exports = {
    mode:'development',
    entry:'./src/main.js',
    output:{
        filename:'js/bundle.js'
    },
    devtool:'source-map',
    module:{
        rules:[
            {
                test:/\.js$/,
                exclude:/node_modules/,
                use:'eslint-loader',
                enforce:'pre'
            },
            {
                test:/\.(png|jpe?g|gif)$/,
                use:{
                    loader:'file-loader',
                    options:{
                        outputPath:'img',
                        name:'[name]-[hash:8].[ext]',
                        esModule: false
                    }
                }
            },
            {
                test:/.css$/,
                use:[
                    'style-loader',
                    'css-loader'
                ]
            },
            {
                test:/.less$/,
                use:[
                    'style-loader',
                    'css-loader',
                    'less-loader'
                ]
            },
            {
                test:/\.vue$/,
                use:'vue-loader'
            },
            {
                test:/\.js$/,
                use:{
                    loader:'babel-loader',
                    options:{
                        presets:['@babel/preset-env']
                    }
                },
                exclude: /node_modules/
            }
        ]
    },
    plugins:[
        new VueLoaderPlugin(),//它的职责是将你定义过的其它规则复制并应用到 .vue 文件里相应语言的块。例如，如果你有一条匹配 /\.js$/ 的规则，那么它会应用到 .vue 文件里的 <script> 块。
        new HtmlWebpackPlugin({
            title:'Vue-app-base',
            template:'./public/index.html'
        })
        
    ]
}